package org.example;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@RestController
public class TestControll {

    @Autowired
    private BloomFilterService bloomFilterService;

    @Autowired
    private UserService userService;

    private  List<User> list;

    @PostConstruct
    public void init() {
        list = userService.load();
        System.out.println(list.size());
        list.stream().forEach(item -> {
            bloomFilterService.add(item.getVin());
        });
        System.out.println(bloomFilterService.ct());
    }

    @GetMapping("/t")
    public String t() {
        List<String> list1 = new ArrayList<>();
        int index = 0;
        do {
            list1.add(UUID.randomUUID().toString());
            index++;
        } while (index < 10000);

        list1.stream().forEach(item -> {
            boolean bl = bloomFilterService.mightContain(item);
            if (bl) {
                System.out.println(item + " ------------1");
            }
        });
        System.out.println("--------------1");
        list1.clear();
        return "ok";
    }

    @GetMapping("/t1")
    public String t1() {
        list.stream().forEach(item -> {
            boolean bl = bloomFilterService.mightContain(item.getVin());
            if (!bl) {
                System.out.println(item.getVin() + " ------------1");
            }
        });
        System.out.println("--------------2");
        list.clear();
        return "ok";
    }

    @GetMapping("/t2")
    public String t2() {
        list = userService.load();
        list.stream().forEach(item -> {
            bloomFilterService.add(item.getVin());
        });
        System.out.println(bloomFilterService.ct());
        return "ok";
    }

    @GetMapping("/t3")
    public boolean t3(String vin) {
       return bloomFilterService.mightContain(vin);
    }

     @GetMapping("/t4")
    public long t4() {
       return bloomFilterService.ct();
    }
}
